package net.peelmeagrape.hibernate.config;

import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;

/**
 * Custom subclass of spring session factory bean that allows annotated classes.
 */
public class LocalSessionFactoryBean
        extends org.springframework.orm.hibernate3.LocalSessionFactoryBean
{
	private Class[] annotatedClasses;

    public LocalSessionFactoryBean()
    {
        setConfigurationClass(HibernateConfiguration.class);
    }

    protected void postProcessConfiguration(Configuration config) throws HibernateException
    {
        HibernateConfiguration hibernateConfiguration = (HibernateConfiguration) config;
        if (this.annotatedClasses != null) {
            for (int i = 0; i < this.annotatedClasses.length; i++) {
                Class annotatedClass = this.annotatedClasses[i];
                hibernateConfiguration.addAnnotatedClass(annotatedClass);
            }
        }
    }

    public Class[] getAnnotatedClasses()
    {
        return annotatedClasses;
    }

    public void setAnnotatedClasses(Class[] annotatedClasses)
    {
        this.annotatedClasses = annotatedClasses;
    }
}
